<!DOCTYPE html>
<html xmlns:wb="http://open.weibo.com/wb">
	<head>
		<meta property="wb:webmaster" content="84a0990950b88867" />
		<meta charset="utf-8" />
		<title></title>
		<script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js" ></script>
		<script src="http://tjs.sjs.sinajs.cn/open/api/js/wb.js?appkey=2622607904&debug=true" type="text/javascript" charset="utf-8"></script>
	</head>
	<body>
		<script>
			$(function() {
				console.log(code);
			});
			function getUrlParam(name) {
				var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
				var r = window.location.search.substr(1).match(reg);
				return r != null ? r[2] : null;
			}

			var code = getUrlParam("code");
			
			function token(){
				WB2.anyWhere(function(W){
    				//数据交互
						W.parseCMD('oauth2/access_token', function(oResult, bStatus) {
							if(bStatus) {
								//to do something...
								console.log(oResult);
							}
						}, {
							"code": code,
							"client_id": "2622607904",
							"client_secret": "c61f0fa27ed3229f30f1c9613261d41f",
							"grant_type": "authorization_code",
							"redirect_uri": "http://xxmengnan.gitee.io:5501/"
						}, {
							method : 'post',
							cache_time : 30
						});
					});
				// $.ajax({
				// 	url:"https://api.weibo.com/oauth2/access_token?client_id=2622607904&client_secret=c61f0fa27ed3229f30f1c9613261d41f&grant_type=authorization_code&redirect_uri=http%3A%2F%2Flocalhost%3A5500%2Findex.html&code="+code,
				// 	type:'GET',
				// 	dataType:'jsonp',   //[重要],默认是支持jsonp格式数据的返回可解决跨域问题；
				// 	function(data){
				// 		console.log(data);
				// 	}
				// });
			}
			function longintoken() {
				window.open("https://api.weibo.com/oauth2/authorize?client_id=2622607904&redirect_uri=http%3A%2F%2Fxxmengnan.gitee.io%3A5501%2F");
				
				// WB2.login(function() {
				// 	//callback function
				// 	console.log();
					
				// });
				
			}

			function xx() {
				WB2.anyWhere(function(W){
    				//数据交互
						W.parseCMD('/users/show.json', function(oResult, bStatus) {
							if(bStatus) {
								//to do something...
							}
						}, {
							"uid": '',
							"appkey": 1352222456,
							"scope": null,
							"create_at": 1352267591,
							"expire_in": 157679471
						}, {
							method : 'post',
							cache_time : 30
						});
					});
			}

		</script>
	</body>
	<div>
		<button onclick="longintoken()">登录授权</button>
		<button onclick="token()">token</button>
		<button onclick="">取消授权</button>
	</div>
</html>
